package cn.com.tbshuda.mysql.mysql.acpt;


import cn.com.tbshuda.mysql.mysql.Bean.UserInfo;
import cn.com.tbshuda.mysql.mysql.config.MethodArgumentNotException;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * 操作日志使用spring event异步入库
 *
 * @author wsd
 * @date 2019-07-01 15:15
 */
@Slf4j
@Aspect
@Component
public class NotNameAspect {

    @Pointcut("@annotation(NotName)")
    public void NotNameAspect() {
        System.out.println("注解了NotNameAspect");
    }

    @Around("NotNameAspect()")
    public void aroundAdvice(JoinPoint proceedingJoinPoint) throws MethodArgumentNotException {
        System.out.println("before");
            Object[] args = proceedingJoinPoint.getArgs();
            if(args.length==0){
                throw new MethodArgumentNotException("参数为空");
            }
            for(Object o :args){
                System.out.println("切入方法的参数："+o);
                if(o instanceof UserInfo){
                    System.out.println("成功了");
                    UserInfo userInfo = (UserInfo) o;
                }else{
                    System.out.println("没有这个参数");
                    throw new MethodArgumentNotException("没有传UserInfo");
                }
            }

        System.out.println("after");
    }


}
